package com.imooc;

import com.imooc.controller.intercept.MInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfigure extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        registry.addResourceHandler("/**")
                // .addResourceLocations("file:D:/Java_code/imooc-video-dev/");
                //这里一个
                .addResourceLocations("file:/usr/local/res/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
    }

    @Bean
    public MInterceptor initIntercept() {
        return new MInterceptor();
    }

    /**
     * 配置拦截器  暂时注释  方便swagger测试
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //  registry.addInterceptor(initIntercept())
        //  .addPathPatterns("/user/**")
        //   ;
        super.addInterceptors(registry);
    }
}
